Add configs to disable unused APIs#960
Conversation
|
Thanks @flynd. We will need a way to test the configuration options in CI. |
I started looking at this, but the standard examples create a signature and then verifies it. When building without signature creation the example code needs to do something else so I'm not sure what would be appropriate here. |
We already have https://github.com/pq-code-package/mldsa-native/blob/main/examples/basic/expected_signatures.h. This could be extended also with keys, then you could implement keygen, sign, and verify separately. |
e061e08 to
abee80e
Compare
|
@mkannwischer : I've added an example that is pretty close to the actual configuration I'm using (except I omitted MLD_CONFIG_REDUCE_RAM in the example). |
abee80e to
3c6b183
Compare
3c6b183 to
c399012
Compare
|
@mkannwischer: It's been a month. Is there any chance that you might have time to look at this now? Or is there something more that I should try to add to make it easier/better? |
Apologies for the long delay! We've been busy with getting everything ready for our RWC talk. |
93a41ee to
3a2bd94
Compare
4e2653a to
2631ce8
Compare
|
I checked the updates you made and found a condition that had been lost, causing mld_rej_uniform_eta_table to be included even if key generation is disabled. |
2631ce8 to
751168f
Compare
When building with MLD_CONFIG_SERIAL_FIPS202_ONLY or MLD_CONFIG_REDUCE_RAM, Keccak-f1600x2/x4 is not used and can be skipped. Signed-off-by: Anders Sonmark <Anders.Sonmark@axis.com>
Only one table is used for each parameter set, so add conditions to remove the unused table from non-shared builds. Signed-off-by: Anders Sonmark <Anders.Sonmark@axis.com>
751168f to
a8f9fdb
Compare
|
@mkannwischer : I have rebased the stack and cleaned up the commits by incorporating your formatting changes into my commits. The only difference from the previous stack is that I've re-added #if conditions around some tables that were lost in the formatting fix. |
Make it possible to exclude key generation when not needed, together with all internal functions not needed for signature creation or verification. Signed-off-by: Anders Sonmark <Anders.Sonmark@axis.com>
Make it possible to exclude signature creation when not needed, together with all internal functions not needed for key generation or signature verification. Signed-off-by: Anders Sonmark <Anders.Sonmark@axis.com>
Make it possible to exclude signature verification when not needed, together with all internal functions not needed for key generation or signature creation. Signed-off-by: Anders Sonmark <Anders.Sonmark@axis.com>
Make it possible to exclude code only used for signature creation or verification. Signed-off-by: Anders Sonmark <Anders.Sonmark@axis.com>
Make it possible to exclude code only used for key generation or verification. Signed-off-by: Anders Sonmark <Anders.Sonmark@axis.com>
Make it possible to exclude code only used for key generation or signature creation. Signed-off-by: Anders Sonmark <Anders.Sonmark@axis.com>
Make it possible to exclude the wrapper APIs if not needed and build only the internal API functions. Signed-off-by: Anders Sonmark <Anders.Sonmark@axis.com>
Same as disabled_apis but with native arithmetic and FIPS-202 backends enabled, testing four disabled API combinations across all three parameter sets. Signed-off-by: Matthias J. Kannwischer <matthias@zerorisc.com>
a8f9fdb to
7e22dd8
Compare
Signed-off-by: Matthias J. Kannwischer <matthias@zerorisc.com>
c1abbda to
8c53a94
Compare
Thanks for your help @flynd - I ran out of time when I looked at this last time. This PR adds quite a bit of additional pre-processor conditionals that make maintanance harder, but at the moment I don't see a better way to achieve the same, and I quite like the feature to disable APIs. What is left is to run full CI (which only works for PRs from local branches) - I have created #1000 for that . We'll also need approval by @hanno-becker. @flynd thanks for your many contributions so far! Would you like me to add you as a contributor to mldsa-native/mlkem-native? Then you could create local branches and we save this extra step above. That would also make merging easier as we do not need to involve both @hanno-becker and me for simple changes. |
|
Closing this in favour of #1000 to avoid confusion. |
I agree that splitting sign.c into separate files is probably a good idea, but as you've already pointed out there is a lot of code outside sign.c that is also specific to only some of the main operations so there would still remain a lot of ifdefs.
I was wondering why you were always duplicating my PRs. I have not worked much with github so thank you for explaining the reason behind this.
I don't have anything else large after this one, but it isn't unlikely that I'll find something more minor that I want to contribute so @mkannwischer please add me so it can be done without the extra steps. What I have locally right now is declaring all the tables as static to hide the linker symbols from other parts of the build. I'm not sure if it is okay to use MLD_CONFIG_INTERNAL_API_QUALIFIER for things that aren't functions so I don't know if I should try to push that. |
Maybe further splitting is called for later, but starting with sign.c sounds like a good idea.
It's actually the AWS EC2 auth that doesn't work from forks as the auth tokens are not available. This may be a configuration issue (only the Linux Foundation staff can change the org configuration), but we have not yet found the time to look into it. It feels like we will soon have to do it because this approach clearly doesn't scale.
Nice, I have added you in pq-code-package/tsc#207 and you should have gotten an e-mail about it. This should also allow you to make changes to #1000. Feel free to do that. |
Thank you @mkannwischer. I was able to push an update for that PR, but the CI gets the same "nix: command not found" as when I pushed via my forked repo so something more seems to be needed. |
The The actual error is: Which suggestts you have not run |
Ah, I see. I opened the job page and the nix error was the only thing that stood out as an error there so I assumed that was what the issue that was causing it to fail. I have managed to run the autogen script locally now. I got some weirdness in unrelated files that I will assume is due to my slightly outdated Debian system, but I at least got the formatting changes for the ifdefs so I could fix those and the lint test has passed this time. Thank you again for explaining. |
Yes, the output of the lint script is really not great in CI :( Sorry. I have opened pq-code-package/mlkem-native#1638 to improve this.
Nice! |
The large diff I got was a bunch of assembly files that changed hex constants to decimal values. I'm not sure if that is clang-format or something else causing it. |
Ahh, no then it's not clang-format. It's our This is also related to our reassembly soundness risk that the object code that is verified in HOL-Light may be different from the object code your assembler actually produces (see https://github.com/pq-code-package/mlkem-native/blob/ddbc21d20d08467541317e3c501693fb0d9c309e/SOUNDNESS.md?plain=1#L389 and also the corresponding issue pq-code-package/mlkem-native#1602). As for Installation is straightforward: https://nixos.org/download/ |
Add configs to disable key generation, signature creation, and/or signature verification to reduce the library size when not needing only one or two of these.
Also adds a config to disable all but the internal APIs, allowing for example to build only crypto_sign_verify_internal() and exclude everything else.
Resolves #941